#include<bits/stdc++.h>
#define int long long
#define db double
using namespace std;
const int N=1e5+5;
const db eps=1e-10;
int t,n,m,k,l,v,las,p[N];
db q[N];bool vis[N];
bool check(db l,db r){
    int x=lower_bound(q+1,q+m+1,l)-q;
    int y=lower_bound(q+1,q+m+1,r)-q-1;
    return y>=x;
}struct car{int d,v,a;}a[N],b[N];
inline bool cmp(car x,car y){
    return (db)(x.d+(v*v-x.v*x.v)/2.0/x.a)<(db)(y.d+(v*v-y.v*y.v)/2.0/y.a);
}bool check(){
    for(int i=1;i<=n;++i){
        if(!vis[i])continue;
        if(a[i].a>0){
            if(a[i].v>v&&a[i].d<=p[las])114514;
            else if(v*v-a[i].v*a[i].v<(p[las]-a[i].d)*2*a[i].a&&p[las]>=a[i].d)114514;
            else return 1;
        }else if(a[i].a==0){
            if(a[i].v>v&&a[i].d<=p[las])114514;
            else return 1;
        }
    }return 0;
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>t;p[0]=q[0]=-1;
    while(t--){
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;++i)
            cin>>a[i].d>>a[i].v>>a[i].a,vis[i]=0;
        for(int i=1;i<=m;++i)
            cin>>p[i],q[i]=p[i];
        int ans=k=las=0;
        for(int i=1;i<=n;++i){
            if(a[i].a>0){
                if(a[i].v>v&&a[i].d<=p[m])++ans,vis[i]=1;
                else if(v*v-a[i].v*a[i].v<(p[m]-a[i].d)*2*a[i].a&&p[m]>=a[i].d)++ans,vis[i]=1;
            }else if(a[i].a==0){
                if(a[i].v>v&&a[i].d<=p[m])++ans,vis[i]=1;
            }else{
                if(a[i].v>v&&check(a[i].d,a[i].d+(db)(v*v-a[i].v*a[i].v)/2.0/a[i].a-eps))++ans,b[++k]=a[i];
            }
        }cout<<ans<<' ';ans=0;
        sort(b+1,b+k+1,cmp);
        for(int i=1,j=0;i<=k;++i){
            if(p[j]<b[i].d){
                ++ans;
                while(j<m&&(q[j+1]<(db)(v*v-b[i].v*b[i].v)/2.0/b[i].a+b[i].d))++j;
                las=j;
            }
        }if(check())++ans;
        cout<<m-ans<<'\n';
    }
    return 0;
}